﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Clipper.BLL;
using Clipper.Model.DataBaseModel;
using ClipperBaseUI.Controls;
using Clipper.ClipperUserControl;
using Clipper.Model.Interface;
using Global;

namespace Clipper.ClipperWindow
{
    /// <summary>
    /// WinAutoStandardCurveData.xaml 的交互逻辑
    /// </summary>
    public partial class WinAutoStandardCurveData : BaseWindow
    {

        private ConnectionClass selectRowChange;
        Clipper.BLL.DetectItems bll = new Clipper.BLL.DetectItems();
        Clipper.Model.DetectItems model = new Clipper.Model.DetectItems();
        Clipper.Model.DetectItems modelVar = null;
        public WinAutoStandardCurveData()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Hide();
        }

        private void BaseWindow_Loaded(object sender, RoutedEventArgs e)
        {
            DetectItems detectItem = new DetectItems();

            comboBox.ItemsSource = detectItem.GetModelList("");
        }
        BLL.SampleInfo mSampleBll = new BLL.SampleInfo();

        BLL.DataBaseBLL.StandardCurveData standardBll = new BLL.DataBaseBLL.StandardCurveData();
        /// <summary>
        /// 操作工作列表的地方
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (comboBox.Text.Equals("FIB") && textBox.Text.Equals(""))
            {
                //弹框提示不能为空
            }

            ServiceProvider.SampleConcentration = Convert.ToDouble(textBox.Text);

            this.Close();

            //添加到工作列表 
            ////  Model.TestTubeInfo _testTube = (Model.TestTubeInfo)this.datWorkSheet.SelectedCells[0].Item;
            Model.TestTubeInfo _testTube = new Model.TestTubeInfo();
            ServiceProvider.SelectedValues = comboBox.Text;  //当前选中值  
                                                             //获取当前选中项的列表信息  
            model = GetModel(ServiceProvider.SelectedValues);
           
             
           
            List<double> conlist; //声明集合
            if (standardBll.CheckExist(comboBox.Text))
            {
                StandardCurveData standard = standardBll.GetModel(comboBox.Text);
                conlist = ServiceProvider.Monitor.GetConcentrationList(standard);
                ServiceProvider.DoTestCount = conlist.Count;  //给全局的实验次数赋值
            }
            else
            {
                //提示数据库不能计算检测的次数 请先记录
                return;
            }
            for (int i = 0; i < conlist.Count; i++)
            {
                if (i == 0 && ServiceProvider.SelectedValues.Equals("FIB"))
                {
                    modelVar = GetModel(ServiceProvider.SelectedValues + "-1"); //查询FIB试剂检测项

                    for (int m = 0; m < 2; m++)
                    {
                        _testTube.SampleID = i + 1;
                        mSampleBll.AddSampleItem(_testTube.SampleID, model.detectItem); //添加样本的检测项
                        mSampleBll.AddSampleItem(_testTube.SampleID, model.detectItem); //添加样本的检测项
                                                                                        //modelVar = new Clipper.Model.DetectItems();
                                                                                        //modelVar = model;
                                                                                        //modelVar.bloodAmount = 20 - m * 10;
                                                                                        //modelVar.reagentAmount1 = Convert.ToByte(80 + m * 10);
                        if (m == 0)
                        {
                            ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i].DetectItems.Add(modelVar);
                            ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i].DetectItems.Add(modelVar);
                        }
                        else
                        {
                            ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i].DetectItems.Add(model);
                            ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i].DetectItems.Add(model);
                        }
                    }
                    i = 2;
                }
                _testTube.SampleID = i;
                mSampleBll.AddSampleItem(_testTube.SampleID, model.detectItem); //添加样本的检测项               
                mSampleBll.AddSampleItem(_testTube.SampleID, model.detectItem); //添加样本的检测项               
                ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i - 1].DetectItems.Add(model);
                ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[i - 1].DetectItems.Add(model);
            }
            //ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[0].DetectItems[0].bloodAmount = 20;
            //ServiceProvider.WorkSheetVM.TestTubeShelfList[0].TestTubeInfoList[0].DetectItems[0].reagentAmount1 = 80;


            CommonClass.WinDetect.ShowDialog();  //弹出框框进行显示数据
        }

        //实例化接口
        public void incetanceConnection(ConnectionClass model)
        {
            this.selectRowChange = model;
        }


        public Clipper.Model.DetectItems GetModel(string detectItem)
        {
            //Clipper.BLL.DetectItems bll = new Clipper.BLL.DetectItems();
            //Clipper.Model.DetectItems model = new Clipper.Model.DetectItems(); 
            return bll.GetModel(detectItem);
        }

        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((Model.DetectItems)comboBox.SelectedValue).detectItem.Equals("FIB"))
            {
                //显示要输入的浓度
                textBlock1.Text = "请输入要FIB定标血浆浓度";
            }
        }
    }
}
